#include <windows.h>
#include <shlobj.h>
#include <iostream>

int main() {
    BROWSEINFO browseInfo = { 0 };
    browseInfo.hwndOwner = NULL; // 父窗口句柄，这里设为NULL
    browseInfo.lpszTitle = "选择文件夹"; // 窗口标题
    browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; // 只选择文件夹并使用新样式
    LPITEMIDLIST itemIdList = SHBrowseForFolder(&browseInfo);
    if (itemIdList != NULL) {
        TCHAR folderPath[MAX_PATH];
        SHGetPathFromIDList(itemIdList, folderPath);

        // 打印文件夹路径
        std::cout << "选择的文件夹路径：" << folderPath << std::endl;

        // 释放资源
        IMalloc* imalloc = NULL;
        if (SUCCEEDED(SHGetMalloc(&imalloc))) {
            imalloc->Free(itemIdList);
            imalloc->Release();
        }
    }

    return 0;
}